import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../views/Home.vue";
import Login from "../views/Login.vue";
import UserInfo from "@/views/UserInfo.vue";
import Record from "@/views/alarm/Record.vue";
import Server from "@/views/alarm/Server.vue";
import MailConfig from "@/views/alarm/MailConfig.vue";
import Menu from "@/views/sys/Menu.vue";
import RecordEcharts from "@/views/alarm/RecordEcharts.vue";
import Silence from "@/views/alarm/Silence.vue";
import Convergence from "@/views/alarm/Convergence.vue";

Vue.use(VueRouter);

//解决编程式路由往同一地址跳转时会报错的情况
const originalPush = VueRouter.prototype.push;
const originalReplace = VueRouter.prototype.replace;
//push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
	if (onResolve || onReject)
		return originalPush.call(this, location, onResolve, onReject);
	return originalPush.call(this, location).catch((err) => err);
};
//replace
VueRouter.prototype.replace = function push(location, onResolve, onReject) {
	if (onResolve || onReject)
		return originalReplace.call(this, location, onResolve, onReject);
	return originalReplace.call(this, location).catch((err) => err);
};

const routes = [{
		path: "/",
		name: "Login",
		component: Login,
		hidden: true
	},
	{
		path: "/home",
		name: "告警管理",
		component: Home,
		children: [{
				path: "/alarm/recordEcharts",
				name: "记录图表",
				component: RecordEcharts
			},
			{
				path: "/alarm/record",
				name: "告警记录",
				component: Record
			},
			{
				path: "/alarm/server",
				name: "服务列表",
				component: Server
			},
			{
				path: "/alarm/mailConfig",
				name: "邮件配置",
				component: MailConfig
			},
			{
				path: "/alarm/convergence",
				name: "收敛配置",
				component: Convergence
			},
			{
				path: "/alarm/silence",
				name: "静默配置",
				component: Silence
			},
		]
	},
	{
		path: "/home",
		name: "系统管理",
		component: Home,
		children: [{
			path: "/sys/menu",
			name: "菜单管理",
			component: Menu
		}, ]
	},
	{
		path: "/home",
		name: "个人中心",
		component: Home,
		children: [{
			path: "/userInfo",
			name: "个人中心",
			component: UserInfo
		}, ]
	},
];

const router = new VueRouter({
	routes,
});

export default router;